package servlet.customer;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Customer;
import service.CustomerService;
import util.JsonTool;

@WebServlet("/CustomerInfoServlet")
public class CustomerInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public CustomerInfoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 更新客户信息
		Customer customer = (Customer) request.getSession().getAttribute("customer");
		customer = new CustomerService().getCustomerById(String.valueOf(customer.getId())).list.get(0);
		request.getSession().setAttribute("customer", customer);
		// 回传客户信息
		String json = JsonTool.objectToJson(customer);
		response.getWriter().write(json);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
